package com.qingcloud.fexecutor.base.pojo;

import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;

import java.io.Serializable;

/**
 * 基础分页参数
 *
 * @author wangjinnan
 */
@Getter
@Setter
@Accessors(chain = true)
public class BasePageParam implements Serializable {

    @ApiModelProperty(value = "第多少页(从1开始)", example = "1", required = true)
    private Integer page;

    @ApiModelProperty(value = "每页显示记录数", example = "10", required = true)
    private Integer size;

    @ApiModelProperty(value = "分页偏移量，不需要传参", example = "0", hidden = true)
    private Integer offset;

    /**
     * 根据页码和数据量获取查询偏移
     */
    public Integer getOffset() {
        if (page != null && size != null) {
            return (page - 1) * size;
        }
        return 0;
    }
}
